// 过滤器 对元素数据进行处理
// 定义过滤器
Vue.filter('toGender',function (value) {
    return value ? '男':'女';
});
Vue.config.keyCodes.f1 = 112;
let app = new Vue({
    el:'#root',
    data:{
        userData:Mock.mock({'data|10':[{
                name:'@cname',
                gender:'@boolean',
                city:'@city',
                phoneNumber:/^1[35789]\d{9}$/,
                age:'@integer(16,30)'
            }]}).data,
        ftBar:['男生','女生','20以下','移动'],
        selectedKey:-1
    },
    methods:{
        clickToDel(index){
            this.show = !this.show;
            this.userData.splice(index,1);
        },
        fn(){
            console.log(this.username);
        },
        select(key){
            this.selectedKey = (key);
        }
    },

    computed:{
        filterUser:function () {
            // 改写四
            let selectedFns = {
                '-1':() => true,
                0:value => value.gender,
                1:value => !value.gender,
                2:value => value.age < 20,
                3:value => /^1[3458]/.test(value.phoneNumber)
            };
            return this.userData.filter(selectedFns[this.selectedKey]);
        }
    }
});

